# this file creates maximum entropy variables for hellwig example
# ---------------------------------------------------------------
setwd("~/Dropbox/Benton-Jordan-Philips/final-JOP-replication")
library(meboot)
library(haven)


# grab Tim's data:
ukdata1 <- as.data.frame(read_dta("data/hellwig/ukdata1.dta"))
head(ukdata1)

set.seed(13098)

create.bootstraps <- function(y, first.obs, last.obs, n) {
  me.boot.store <- meboot(y[first.obs:last.obs], reps = n)
  the.me.boots <- data.frame(me.boot.store$ensemble)
  names(the.me.boots) <- paste0("meboot_y_", 1:n)
  time <- first.obs:last.obs
  combined.boot <- data.frame(time, y[first.obs:last.obs], the.me.boots)
  combined.boot
}

combined.boots1 <- create.bootstraps(ukdata1$fdsupp84, first.obs = 1, last.obs = 304, n = 2500) # doing 2500 sims b/c we'll stop once we get 1000 but some might not converge
write.csv(combined.boots1, file = "data/hellwig/hellwig-me.csv")
